<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e"
      >
    </ex_super_table_page>
    <appointmentReport ref="appointmentReportRer"></appointmentReport>
  </div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';
import emitOnFunction from '@/mixin/emit-on-function';

import page_table_model_manage from '@/mixin/page_table_model_manage';
let emitKey = 'warehouse_appointment>confirm'

import appointmentReport from './component/appointment_report';

import transitNoSelect from './component/transitNo_select.vue'
export default {
  title: 'title_warehouse_appointment',
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components:{appointmentReport,transitNoSelect},
  data() {
    return {
      selection: [],
      status: "",
      statusRadioGroup: [
        'label_all',
        ...this.$enumOptions.ScheduleStatusEnum ? this.$enumOptions.ScheduleStatusEnum.filter(it=>!['WAIT_ARRIVE','FINSHED'].includes(it)) : []
      ],
      option: {
        search: {
          model: [
            { label: "label_schedule_code", key: "scheduleCode" },
            { label: "label_waybill_code", key: "transitNo", type:transitNoSelect},
            // { label: "客户信息", key: "customerName", type:customerSelect },
            { label: "label_schedule_status", key: "scheduleStatusEnum",type: 'select', enum: 'ScheduleStatusEnum' },
            { label: "label_schedule_method", key: "scheduleTypeEnum", type: 'select', enum: 'ScheduleTypeEnum'},
            /*{ label: "到货差异", key: "isDiff",type: 'select', enum: 'YesOrNoEnum' },*/
            { label: "label_expected_arrival_date", key: "expectedDate", type: 'date-picker', attrs: { type: 'datetimerange' }, keyExtra: { _emitKey: 'input', 0: 'expectedBeginDate', 1: 'expectedEndDate' } },
          ],
        },
        actionExtra: [
          { label: "label_schedule_appointment", click: () => this.$refs.appointmentReportRer.show()},
          { label: 'label_export', attrs: { type: "primary" }, click: this.exportExcel },
        ],
        table: {
          url: "/oms-api/client/OmsInboundScheduleClientRpc/selectPage.json",
          // urlDataHandle: this.dataHandle,
          model: this.option_table_model(),
        },
      },
    };
  },
  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },
        { key: 'scheduleCode', label: 'label_schedule_code',width: 150,'show-overflow-tooltip': true},
        { key: 'warehouseName', label: 'label_warehouse_name',width: 140,'show-overflow-tooltip': true},
        { key: 'transitNo', label: 'label_waybill_code',width: 100,'show-overflow-tooltip': true},
        { key: 'scheduleTypeEnum', label: 'label_schedule_method',minWidth: 100,'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "ScheduleTypeEnum")
        },
        { key: 'scheduleStatusEnum', label: 'label_schedule_status',minWidth: 100,'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "ScheduleStatusEnum")
        },
        { key: 'expectedDatetime', label: 'label_expected_arrival_date',minWidth: 160,'show-overflow-tooltip': true,
         formatter: (r, c, v, i) => this.$dateFormat(v)
        },
        { key: 'expectPackagingQty', label: 'label_declare_goods_sum_package_count',minWidth: 160,'show-overflow-tooltip': true},
        { key: 'expectBoxQty', label: 'label_declare_goods_sum_box_count',minWidth: 160,'show-overflow-tooltip': true},
        { key: 'vehicleNo', label: 'label_car_number',minWidth: 100,'show-overflow-tooltip': true},
        { key: 'driverName', label: 'label_driver_name',minWidth: 100,'show-overflow-tooltip': true},
        { key: 'driverPhone', label: 'label_driver_phone',minWidth: 120,'show-overflow-tooltip': true},
        { key: 'volumn', label: 'label_declare_goods_sum_volume',minWidth: 100,'show-overflow-tooltip': true},
        { key: 'weight', label: 'label_declare_goods_sum_weight',minWidth: 100,'show-overflow-tooltip': true},
        { key: 'reporter', label: 'label_declare_user',minWidth: 100,'show-overflow-tooltip': true},
        { key: 'gmtCreate', label: 'label_schedule_appointment_time',minWidth: 100,'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$dateFormat(v)
        },
        /*{ key: 'isDiff', label: '是否差异',minWidth: 100,'show-overflow-tooltip': true,
          formatter: (r,c,v) => this.$enumShow(v, "YesOrNoEnum"),
        },*/
        {
          type: 'operate',
          width: 160,
          operate: [
            {
              label: "label_edit",
              disabled: row => row.scheduleStatusEnum !== "REJECT",
              click: row => this['$refs']['appointmentReportRer'].show({row, edit: true })
            },
            {
              label: "title_appointment_report_detail",
              click: (row, i) => {
                this.$router.push({
                  path: './appointment_report_detail', query: { id: row.id, }
                })
              }
            },
          ]
        }
      ]
    },
    changeStatus(e) {
      this.status = e
      this.getSuperTablePage().loadDataForSearch()
    },
    exportExcel() {
      const params = this.$refs.SuperTablePage.getSearchFormData()

      const scheduleIds = []
      this.selection.forEach(item=>{
        scheduleIds.push(item.id)
      })
      this.$downloadFile({
        url:'/oms-api/client/OmsInboundScheduleClientRpc/exportExcel.json',
        window:true,
        data:{
          ...params,
          scheduleIds:scheduleIds.toString()
        }
      })
    }
  }
};

</script>
<style></style>
